package org.elzat.healthboxgatewayapp.service.implV1;

import org.elzat.healthboxgatewayapp.service.MessageTokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
public class MessageTokenServiceV1 implements MessageTokenService {

    private final ValueOperations<String, String> operations;

    @Autowired
    public MessageTokenServiceV1(RedisTemplate<String, String> template) {
        operations = template.opsForValue();
    }

    @Override
    public Optional<String> getTokenByPhoneNumber(String phoneNumber) {
        String token = operations.get(phoneNumber);
        return token == null ? Optional.empty() : Optional.of(token);
    }
}
